package org.msfj.admin.data.controller;

import org.msfj.admin.model.Holiday;
import org.msfj.admin.vo.HolidayVo;
import org.msfj.admin.model.Holiday;
import org.msfj.admin.vo.HolidayVo;
import org.msfj.admin.model.Holiday;
import org.msfj.admin.vo.HolidayVo;
import org.msfj.common.context.UserContextHandler;
import org.msfj.admin.data.service.HolidayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.msfj.common.base.BaseController;
import org.msfj.common.model.CommonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 系统节假日controller
 * @Author: like
 * @Email: like@deyatong.com
 * @Date: 2017-08-10 17:30:21
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@Api(value = "系统节假日接口", tags = "系统节假日接口")
@RestController
@RequestMapping("data/holiday")
public class HolidayController extends BaseController{

    @Autowired
    private HolidayService holidayService;

    /**
     * 添加系统节假日
     *
     * @param holidayVo
     * @return CommonResult.ok(HolidayVo)
     */
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加系统节假日",notes = "添加系统节假日")
    @ApiImplicitParam(value = "holidayVo",name = "holidayVo",dataType = "org.msfj.admin.vo.HolidayVo",paramType = "query")
    public CommonResult addHoliday(HolidayVo holidayVo){
        Holiday holiday = holidayService.saveOrEdit(holidayVo);
        return CommonResult.ok(holidayService.setOtherProperties(holiday));
    }

    /**
     * 修改系统节假日
     *
     * @param holidayVo
     * @return CommonResult.ok(HolidayVo)
     */
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation(value = "修改系统节假日",notes = "修改系统节假日")
    @ApiImplicitParam(value = "holidayVo",name = "holidayVo",dataType = "org.msfj.admin.vo.HolidayVo",paramType = "query")
    public CommonResult editHoliday(HolidayVo holidayVo){
        Holiday holiday = holidayService.saveOrEdit(holidayVo);
        return CommonResult.ok(holidayService.setOtherProperties(holiday));
    }

    /**
     * 逻辑删除系统节假日
     *
     * @param holidayVo
     * @return CommonResult.ok(HolidayVo)
     */
    @PostMapping("/del")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统节假日",notes = "逻辑删除系统节假日")
    @ApiImplicitParam(value = "holidayVo",name = "holidayVo",dataType = "org.msfj.admin.vo.HolidayVo",paramType = "query")
    public CommonResult delHoliday(HolidayVo holidayVo){
        Holiday holiday = holidayService.delById(holidayVo);
        return CommonResult.ok(holidayService.setOtherProperties(holiday));
    }

    /**
     * 逻辑删除系统用户信息
     * @param ids
     * @return CommonResult.ok()
     */
    @PostMapping("/dels")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统节假日",notes = "逻辑删除系统节假日")
    @ApiImplicitParam(value = "ids",name = "ids",dataType = "java.util.List",paramType = "query")
    public CommonResult delUsers(@RequestParam(value = "ids[]",required = false) List<String> ids){
        Holiday holiday = new Holiday();
        holidayService.delByIds(ids, holiday);
        return CommonResult.ok();
    }

    /**
     * 真实删除系统节假日
     *
     * @param holidayVo
     * @return CommonResult.ok()
     */
    @PostMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "真实删除系统节假日",notes = "真实删除系统节假日")
    @ApiImplicitParam(value = "holidayVo",name = "holidayVo",dataType = "org.msfj.admin.vo.HolidayVo",paramType = "query")
    public CommonResult deleteHoliday(HolidayVo holidayVo){
        holidayService.trueDelById(holidayVo);
        return CommonResult.ok();
    }

    /**
     * 根据id查找系统节假日
     *
     * @param holidayVo
     * @return CommonResult.ok(HolidayVo)
     */
    @GetMapping("/get")
    @ResponseBody
    @ApiOperation(value = "根据id查找系统节假日",notes = "根据id查找系统节假日")
    @ApiImplicitParam(value = "holidayVo",name = "holidayVo",dataType = "org.msfj.admin.vo.HolidayVo",paramType = "query")
    public CommonResult getHoliday(HolidayVo holidayVo){
        Holiday holiday = holidayService.getById(holidayVo.getId());
        return CommonResult.ok(holidayService.setOtherProperties(holiday));
    }

    /**
     * 根据翻页参数、搜索参数查找系统节假日
     *
     * @param holidayVo
     * @param page 当前第几页
     * @param rows 每页多少条记录
     * @return CommonResult.ok(PageInfo<HolidayVo>)
     */
    @GetMapping("/list")
    @ResponseBody
    @ApiOperation(value = "根据翻页参数、搜索参数查找系统节假日",notes = "根据翻页参数、搜索参数查找系统节假日")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "holidayVo",name = "holidayVo",dataType = "org.msfj.admin.vo.HolidayVo",paramType = "query"),
        @ApiImplicitParam(name = "page",value = "page",dataType = "Integer",paramType = "path"),
        @ApiImplicitParam(name = "rows",value = "rows",dataType = "Integer",paramType = "path")
    })
    public CommonResult findHolidayList(HolidayVo holidayVo, Integer page, Integer rows){
        PageInfo<HolidayVo> holidayVoPageInfo = holidayService.getByHoliday(holidayVo,page,rows);
        return CommonResult.ok(holidayVoPageInfo);
    }

    /**
     * 根据搜索参数查找所有系统节假日
     *
     * @param holidayVo
     * @return CommonResult.ok(List<HolidayVo>)
     */
    @GetMapping("/getAll")
    @ResponseBody
    @ApiOperation(value = "根据搜索参数查找所有系统节假日",notes = "根据搜索参数查找所有系统节假日")
    @ApiImplicitParam(value = "holidayVo",name = "holidayVo",dataType = "org.msfj.admin.vo.HolidayVo",paramType = "query")
    public CommonResult getAllHoliday(HolidayVo holidayVo){
        List<HolidayVo> holidayVoList = holidayService.getAllHoliday(holidayVo);
        return CommonResult.ok(holidayVoList);
    }

    /**
     * 保存节假日
     * @param year
     * @param holiday
     * @return
     */
    @PostMapping("/addHoliday")
    @ResponseBody
    @ApiOperation(value = "添加系统角色用户关联信息", notes = "添加系统角色用户关联信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "year", name = "year", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(value = "value", name = "value", dataType = "java.util.List", paramType = "query")
    })
    public CommonResult addHoliday(String year, @RequestParam(value = "value[]",required = false) List<String> holiday){
        holidayService.saveHoliday(year, holiday, UserContextHandler.getUserID());
        return CommonResult.ok();
    }
}
